﻿@model IMS_Partner
@{
    Layout = "_LayoutMobile";
    ViewBag.Title = (Model.ID > 0 ? "修改" : "新增") + "客户";
}
@section header {
    <style>
        .bottombutton {
            padding: 10px;
        }
    </style>
}
<van-nav-bar title="客户"
             left-arrow
             :fixed="true"
@@click-left ="goBack">
</van-nav-bar>
<van-cell-group>
    <van-field v-model="model.Name"
               input-algn='right'
               label="单位名称"
               placeholder="请输入单位名称"
               required
               clearable
               @@change="handleChangeName"></van-field>
    <van-field v-model="model.PYCode"
               input-algn='right'
               label="拼音助记码"
               placeholder="请输入拼音助记码"
               clearable
               @@change="handleChangePYCode"></van-field>
    <van-field v-model="model.Code"
               input-algn='right'
               label="单位编码"
               placeholder="请输入单位编码"
               clearable></van-field>
    <van-field v-model="model.Phone"
               input-algn='right'
               label="电话"
               placeholder="请输入电话"
               clearable></van-field>
    <van-field v-model="model.Fax"
               input-algn='right'
               label="传真"
               placeholder="请输入传真"
               clearable></van-field>
    <van-field v-model="model.ContactMan"
               input-algn='right'
               label="联系人"
               placeholder="请输入联系人"
               clearable></van-field>
    <van-field v-model="model.ContactPhone"
               input-algn='right'
               label="联系电话"
               placeholder="请输入联系电话"
               clearable></van-field>
    <van-field v-model="model.Location"
               input-algn='right'
               label="详细地址"
               placeholder="请输入详细地址"
               clearable></van-field>
    <van-field v-model="model.Comment"
               input-algn='right'
               label="备注"
               placeholder="请输入备注"
               clearable></van-field>
</van-cell-group>
<div class="bottombutton">
    <van-button type="primary" block @@click="onSave">提交</van-button>
</div>
@section footer {
    <script src="~/js/pinyin.js" asp-append-version="true"></script>
    <script type="text/javascript">
            var modelJson=@(Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model, new Newtonsoft.Json.JsonSerializerSettings()
                  {
                      DateFormatString = "yyyy-MM-dd HH:mm:ss"
                  })));
            var modelData = $.extend(modelJson, {});
        var pageApp = new Vue({
             el: '#app',
                data: {
                        active:'my',
                        model:modelData
                },
                    methods: {
                        goBack(){
                            window.location.href = '@(Url.Action("MobileList", "Partner"))';
                        },
                handleChangeName: function () {
                    var _this=this;
                    _this.model = Object.assign({}, _this.model, {
                        PYCode: utils.pinyin.getFirstLetter(_this.model.Name).substr(0, 10),
                    });
                },
                handleChangePYCode: function () {
                    var _this = this;
                    if (!!_this.model.PYCode) {
                        _this.model.PYCode = _this.model.PYCode.toUpperCase().substr(0, 10);
                    }
                },
                        onSave(){
                            const data = this.model;
                            if(!data.Name)
                            {
                                vant.Toast('请输入单位名称');
                                return;
                            }
                            utils.ajaxPost('@(Url.Action("Save", "Partner"))', data, function (resp) {
                                console.log(resp.data);
       
                                location.href = '@(Url.Action("MobileViewDetail", "Partner", new { id = "" }))/'+resp.data+'?nc=' + new Date().getTime();
                            }, function (msg) {
                                console.log(msg);
                            });
                        }
                },
            filters: {
                formatDate: function (val) {
                    return utils.formatDate(val, 'yyyy-MM-dd');
                },
            },
        });
        $(function () {
            if(!isMobile())
            {
                    window.location.href = '@(Url.Action("Edit", "Partner"))/' + modelData.ID + '?nc=' + new Date().getTime();
            }
        });

        function isMobile() {
          const regExp = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
          return regExp.test(navigator.userAgent);
        }
    </script>
}